#! /usr/bin/env python
# -*- coding: utf8 -*-

# Alexandre Coster <acoster@rhrk.uni-kl.de>
# AG DBIS - Technische Universität Kaiserslautern

# mXML: Messy XML Generator
# This application generates a dirty (messy) XML file (with changes
# both on the values and the structure) based on a "clean" input

import sys
import random
import zope.interface

import base

if __name__ == "__main__":
    print "You shouldn't be running this file!"
    sys.exit()

class delChars(object):
    zope.interface.implements(base.IAlgorithm)

    name = "delChars"

    def __init__(self, node):
        self.__params = base.node_to_dictionary(node)

        self.__first = 0
        if self.__params["includeFirst"].lower() != "true":
            self.__first = 1

        self.__loffset = 0
        if self.__params["includeLast"].lower() != "true":
            self.__loffset = 1

    def __call__(self, string):
        if len(string) == 1 and (self.__first == 1 or self.__loffset == 1):
            return string

        c   = len(string)
        end = c - self.__loffset

        toDelete = random.randint(self.__first, end)
        string   = string[0:toDelete] + string[toDelete + 1:]

        return string

__plugins__ = (delChars, )
